package de.armar.belt_timer;

import java.awt.GridLayout;

import javax.swing.JPanel;

public class BeltButtonPane extends JPanel {
	private static final long serialVersionUID = 1L;
	private BeltTimer main;
	private TimerButton [] timerbuttons = new TimerButton[30];
	private int beltcount = 15;

	public BeltButtonPane(BeltTimer main) {
		this.setMain(main);
		this.setLayout(new GridLayout(beltcount,1,1,1));
		addAll();	
	}

	private void addAll() {
		for (int i = 0; i < beltcount; i++) {
			timerbuttons[i]=new TimerButton(""+(i+1));
			this.add(timerbuttons[i]);
		}	
	}

	public void increment() {
		beltcount++;
		rebuild();
	}

	public void decrement() {
		beltcount--;
		this.rebuild();
	}

	private void rebuild() {
		this.removeAll();
		this.addAll();
		this.setLayout(new GridLayout(beltcount,1,1,1));
		this.revalidate();
		this.repaint();	
	}

	public void reset() {		
		for (int i = 0; i < beltcount; i++) {		
			timerbuttons[i].reset();
		}		
	}

	public void checkall() {	
		for (int i = 0; i < beltcount; i++) {		
			timerbuttons[i].start();
		}		
	}

	public BeltTimer getMain() {
		return main;
	}

	public void setMain(BeltTimer main) {
		this.main = main;
	}
	
	

}
